import 'package:flutter/material.dart';
import 'package:p_location/alarm/ui/alarm_area_list_page.dart';
import 'package:p_location/alarm/ui/alarm_job_list_page.dart';
import 'package:p_location/alarm/ui/alarm_vehicle_list_page.dart';
import 'package:p_location/common/ui/base_filter_head_list_view.dart';
import 'package:p_location/common/ui/base_filter_tab_page.dart';
import 'package:p_location/user/obj/user_info.dart';

class EmergencyManageTab extends BaseFilterTabPage {
  final int type;
  final bool isHiddenAppbar;

  @override
  BaseFilterTabPageState<BaseFilterTabPage> getState() {
    return new _EmergencyManageTabState();
  }

  EmergencyManageTab({this.type, this.isHiddenAppbar = false})
      : super(isHiddenBack: isHiddenAppbar);
}

class _EmergencyManageTabState
    extends BaseFilterTabPageState<EmergencyManageTab> {
  @override
  List<BaseFilterHeadListView> getTabItemPage() {
    if (UserInfo.isVehicleModuleValid()) {
      return [AlarmAreaListPage(), AlarmVehicleListPage(), AlarmJobListPage()];
    } else {
      return [AlarmAreaListPage(), AlarmJobListPage()];
    }
  }

  @override
  List<Tab> getTabTiles() {
    if (UserInfo.isVehicleModuleValid()) {
      return [Tab(text: '区域人员报警'), Tab(text: '车辆报警'), Tab(text: '作业报警')];
    } else {
      return [Tab(text: '区域人员报警'), Tab(text: '作业报警')];
    }
  }

  @override
  String getTitle() {
    return '报警查看';
  }

  @override
  int getInitialIndex() {
    if (widget.type == 0) {
      //区域人员报警
      return 0;
    }
    if (widget.type == 1) {
      //车辆报警
      if (UserInfo.isVehicleModuleValid()) {
        return 1;
      }
    }
    if (widget.type == 2) {
      //作业报警
      if (UserInfo.isVehicleModuleValid()) {
        return 2;
      } else {
        return 1;
      }
    }
    return 0;
  }
}
